﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GuiAndDb
{
    public partial class CashRegister : Form
    {
        public Product Product { get; set; }

        public CashRegister()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            ProductDB db = new ProductDB();
            Product p = db.GetProductInfo(textBox1.Text);
            dataGridView1.Rows.Add();
            int index = dataGridView1.NewRowIndex;
            dataGridView1.Rows[index - 1].Cells[0].Value = p.name;
            dataGridView1.Rows[index - 1].Cells[2].Value = textBox2.Text;
            dataGridView1.Rows[index - 1].Cells[1].Value = p.price.ToString();
            dataGridView1.Rows[index - 1].Cells[3].Value = Convert.ToInt16(dataGridView1.Rows[index - 1].Cells[1].Value) * Convert.ToInt16(dataGridView1.Rows[index - 1].Cells[2].Value);
            double totalSum = 0;
            for (int i = 0; i < index; i++)
            {
                totalSum += Convert.ToInt16(dataGridView1.Rows[i].Cells[3].Value);

            }
            textBox3.Text = totalSum.ToString();
            textBox1.Text = null;
            textBox2.Text = null;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
            int index = dataGridView1.NewRowIndex;
            double totalSum = 0;
            for (int i = 0; i < index; i++)
            {
                totalSum += Convert.ToInt16(dataGridView1.Rows[i].Cells[3].Value);

            }
            textBox3.Text = totalSum.ToString();
        }


    }
}
